﻿using System.Web.Routing;

namespace ReadyApps.Common
{
    /// <summary>
    /// Provides global methods used in implementing the ReadyApps system.
    /// </summary>
    public static class Application
    {
        #region Constants

        /// <summary>
        /// Represents the key that is used to access the portion of the variable
        /// routing data.
        /// </summary>
        public const string PATH_DATA_KEY = "path";

        #endregion

        #region Static Methods

        /// <summary>
        /// Adds any configured routes to the <see cref="RouteCollection"/> when called.
        /// </summary>
        /// <param name="routes">The <see cref="RouteCollection"/> to add the configured
        /// routes to</param>
        public static void RegisterConfiguredRoutes(RouteCollection routes)
        {
            foreach (var mapping in ReadyAppsSettings.WikiMappings)
            {
                // fix for bug 605 - http://readyapps.codeplex.com/workitem/605
                // Need routing to ignore any requests for *.axd requests so the resource requests can be
                // sent directly to a nested application
                routes.MapPageRoute(
                    mapping.Name,
                    mapping.GetRouteUrl(),
                    mapping.MapTo,
                    true,
                    null,
                    new RouteValueDictionary { { Application.PATH_DATA_KEY, @"([^\.]|\.(?!axd))*" } });
            }
        }

        #endregion
    }
}
